/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Cuahang;
import util.HibernateUtil;

/**
 *
 * @author dell pro
 */
public class CuaHangDAO {
    public static List<Cuahang> layDanhSachCuaHang() {
        List<Cuahang> ds = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "select ch from Cuahang ch";
            Query query = session.createQuery(hql);
            ds = query.list();
        } catch (HibernateException ex) {
                //Log the exception
                System.err.println(ex);
        } finally {
            session.close();
        }
        return ds;
    }
    
    public static Cuahang GetCuaHang(String macuahang){
        Cuahang ch = new Cuahang();
        List<Cuahang> listch = CuaHangDAO.layDanhSachCuaHang();
        for (int i=0;i<listch.size();i++){
            if (macuahang.equals(listch.get(i).getIdcuahang())){
                ch = listch.get(i);
            }
        }
        return ch;
    }
    
}
